import datetime
from applications.extensions import db

from sqlalchemy import UniqueConstraint
class LocationRawYP(db.Model):
    __tablename__ = '货位管理_yp_原料'
    id = db.Column(db.Integer, primary_key=True, comment='编号')
    name = db.Column(db.String(255), comment='货位/库区/仓库名称', nullable=False)
    type = db.Column(db.String(1), comment='仓库类型仓库|库区|货位->0.1.2')
    code = db.Column(db.String(50), comment='仓库二维码',  nullable=False,unique=True)
    details = db.Column(db.String(255), comment='详情')

    parent_id = db.Column(db.Integer, comment='父类编号' )
    icon = db.Column(db.String(128), comment='图标')
    sort = db.Column(db.Integer, comment='排序')
    enable = db.Column(db.Integer, comment='是否开启')
    create_time = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
    update_time = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间')


    # # 创建联合索引
    # __table_args__ = (
    #     UniqueConstraint('code', name='LocationRawYP_code'),
    # )
    def to_dict(self):
        return {column.name: getattr(self, column.name) for column in self.__table__.columns}
class LocationAuxiliaryYP(db.Model):
    __tablename__ = '货位管理_yp_辅料'
    id = db.Column(db.Integer, primary_key=True, comment='编号')
    name = db.Column(db.String(255), comment='货位/库区/仓库名称', nullable=False)
    type = db.Column(db.String(1), comment='权限类型')
    code = db.Column(db.String(50), comment='权限标识',  nullable=False,unique=True)
    details = db.Column(db.String(255), comment='详情')

    parent_id = db.Column(db.Integer, comment='父类编号' )
    icon = db.Column(db.String(128), comment='图标')
    sort = db.Column(db.Integer, comment='排序')
    create_time = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
    update_time = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间')
    enable = db.Column(db.Integer, comment='是否开启')
    # # 创建联合索引
    # __table_args__ = (
    #     UniqueConstraint('code', name='LocationAuxiliaryYP_code'),
    # )
class LocationPackagingYP(db.Model):
    __tablename__ = '货位管理_yp_包材'
    id = db.Column(db.Integer, primary_key=True, comment='编号')
    name = db.Column(db.String(255), comment='货位/库区/仓库名称', nullable=False)
    type = db.Column(db.String(1), comment='权限类型')
    code = db.Column(db.String(50), comment='权限标识', nullable=False,unique=True)
    details = db.Column(db.String(255), comment='详情')

    parent_id = db.Column(db.Integer, comment='父类编号' )
    icon = db.Column(db.String(128), comment='图标')
    sort = db.Column(db.Integer, comment='排序')
    create_time = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
    update_time = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间')
    enable = db.Column(db.Integer, comment='是否开启')
    # # 创建联合索引
    # __table_args__ = (
    #     UniqueConstraint('code', name='LocationPackagingYP_code'),
    # )
class LocationIntermediateYP(db.Model):
    __tablename__ = '货位管理_yp_中间品'
    id = db.Column(db.Integer, primary_key=True, comment='编号')
    name = db.Column(db.String(255), comment='货位/库区/仓库名称', nullable=False)
    type = db.Column(db.String(1), comment='权限类型')
    code = db.Column(db.String(50), comment='权限标识', unique=True, nullable=False)
    details = db.Column(db.String(255), comment='详情')

    parent_id = db.Column(db.Integer, comment='父类编号' )
    icon = db.Column(db.String(128), comment='图标')
    sort = db.Column(db.Integer, comment='排序')
    create_time = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
    update_time = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间')
    enable = db.Column(db.Integer, comment='是否开启')
    # # 创建联合索引
    # __table_args__ = (
    #     UniqueConstraint('code', name='LocationIntermediateYP_code'),
    # )
class LocationFinishedYP(db.Model):
    __tablename__ = '货位管理_yp_成品'
    id = db.Column(db.Integer, primary_key=True, comment='编号')
    name = db.Column(db.String(255), comment='货位/库区/仓库名称', nullable=False)
    type = db.Column(db.String(1), comment='权限类型')
    code = db.Column(db.String(50), comment='权限标识', unique=True, nullable=False)
    details = db.Column(db.String(255), comment='详情')

    parent_id = db.Column(db.Integer, comment='父类编号' )
    icon = db.Column(db.String(128), comment='图标')
    sort = db.Column(db.Integer, comment='排序')
    create_time = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
    update_time = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间')
    enable = db.Column(db.Integer, comment='是否开启')
    # # 创建联合索引
    # __table_args__ = (
    #     UniqueConstraint('code', name='LocationFinishedYP_code'),
    # )